<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@include file="init.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/scrip.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Welcome to Software Engineering Project</title>
</head>
<body>
<div class="master-wrapper-content">								
	<jsp:include page="heading.jsp"></jsp:include>
	<jsp:include page="listCategory.jsp"></jsp:include>
	<div class="container-right">
	<%
		String username = (String) session.getAttribute("username");
		User user = dataManager.getUserWithUserName(username);
		List<YourFavourite> yourFavorites = dataManager.getAllFavoriteByUserId(user.getUserId());
	%>
	<h3>Cac san pham ua thich cua ban</h3>
	
	
	<%
		if(yourFavorites == null || yourFavorites.isEmpty())
		{
	%>
			<h3>Ban chua chon san pham nao</h3>
			<%
				}
				else 
				{
			%>
					<table class="table_product">
				<tr class="header_table">
				<th>Loai bo </th>
				<th>Ten San Pham</th>
				<th>Gia </th>
				
				<th>Them Vao Gio Hang</th>
				</tr>
			<%
				for(YourFavourite y : yourFavorites)
					{
				Product p = dataManager.getProductById(y.getProductId());
			%>
				<tr id="your_favourite_item_<%=y.getYourFavoriteId() %>">
				<td>
					
					
					<input type="button" value="xoa" onclick="delFavouriteItem(<%=y.getYourFavoriteId()%>)"/>
				</td>
				<td>
					<p><%=p.getProductName() %></p>
					<a href="productDetail.jsp?productId=<%=p.getProductId()%>">  <img src="<%="/ECommerce/DisplayImage?path=" + p.getImage() %>"/></a>
				</td>
				
				
				<td>
					<%=p.getPrice() %>
				</td>
				<%
					if(dataManager.checkCartProduct(p.getProductId(), user.getUserId()))
					{
						%>
						<td>
						
						<div id="favouriteToCart_<%=p.getProductId() %>"><input type="button" onclick="favouriteToCart(<%=p.getProductId() %>)" value="Them"/></div>
					
				</td>
				
						<%
					}
					else
					{
						%>
						<td>
						
						<div id="favouriteToCart_<%=p.getProductId() %>">Da co trong <a href="yourCart.jsp">gio hang</a></div>
					
				</td>
						<%
					}
				%>
				
				</tr>
				<%
			}
			
			}
		%>
	
	
	
	</table>
	</div>				
	<div class="clear"></div>
	<jsp:include page="footer.jsp"></jsp:include>					
</div>		
</body>
</html>